#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "./3d-dna.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

if [[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]]; then echo "请输入正确的构建路径"; exit 1; fi
if [[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]]; then echo "请输入正确的安装路径"; exit 1; fi
if [[ "$1" == "$2" ]]; then echo "构建路径与安装路径不能相同，请输入正确的路径"; exit 1; fi

buildpath=$1
installpath=$2
yum install -y wget tar environment-modules
#安装3d-dna运行时环境 jdk
yum install -y java-1.8.0-openjdk python3 python3-matplotlib python3-numpy python3-scipy
#获取3d-dna源码，解压，增加执行权限
wget -t 10 -c -P $buildpath https://codeload.github.com/aidenlab/3d-dna/zip/refs/heads/master
cd $buildpath
unzip master
chmod +x -R $buildpath/3d-dna-master
mkdir $installpath/3d-dna
cp -r $buildpath/3d-dna-master/* $installpath/3d-dna/
cat>"$installpath/3d-dna/3d-dna_modulefiles"<<EOF
#%Module1.0
conflict 3d-dna
variable modfile [file normalize [info script]]
proc getModulefileDir {} {
    variable modfile
    set modfile_path [file dirname \$modfile]
    return \$modfile_path
}
set pwd [getModulefileDir]
set dna \$pwd
setenv dna \$dna
prepend-path PATH \$dna
EOF
rm -rf $buildpath
